package com.mall.shopping.services;

import com.mall.shopping.IItemCategoriesService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Author raohui
 * @Date 2021/6/18 23:27
 */
@Service
public class IItemCategoriesServiceImpl implements IItemCategoriesService {

    @Autowired
    ItemCatMapper itemCatMapper;

    @Autowired
    ProductCateConverter productCateConverter;

    @Override
    public AllProductCateResponse queryItemCategories() {
        AllProductCateResponse allProductCateResponse = new AllProductCateResponse();
        try {
            //无需check
            Example example = new Example(ItemCat.class);
            List<ItemCat> itemCats = itemCatMapper.selectByExample(example);
            List<ProductCateDto> productCateDtos = productCateConverter.items2Dto(itemCats);
            allProductCateResponse.setProductCateDtoList(productCateDtos);
            allProductCateResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            allProductCateResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            return allProductCateResponse;
        } catch (Exception e) {
            allProductCateResponse.setCode(ShoppingRetCode.SYSTEM_ERROR.getCode());
            allProductCateResponse.setMsg(ShoppingRetCode.SYSTEM_ERROR.getMessage());
        }
        return null;
    }
}
